package com.maolong.routing;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class RoutingProductor {
    private static final String EXCHANGE_NAME = "direct_exchange";
    private static final String QUEUE_NAME = "routing_queue_1";
    private static final String QUEUE_NAME2 = "routing_queue_2";

    public static void main(String[] args) throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("182.92.151.172");
        factory.setUsername("maolong");
        factory.setPassword("123456");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.exchangeDeclare(EXCHANGE_NAME, "direct");
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        channel.queueDeclare(QUEUE_NAME2, false, false, false, null);

        channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, "info");
        channel.queueBind(QUEUE_NAME2, EXCHANGE_NAME, "error");
        channel.queueBind(QUEUE_NAME,EXCHANGE_NAME,"info");


        for(int i=0;i<10;i++){
            String message = "routing message"+i;
            channel.basicPublish(EXCHANGE_NAME, "info", null, message.getBytes());
            channel.basicPublish(EXCHANGE_NAME, "error", null, message.getBytes());
        }
    }
}
